const app = require('express')();
const queryList = require('@/models/history-today/history-today');
const { validationResult, check } = require('express-validator');

// 校验规则验证数据
const validator = [
  check('date').isLength({ min: 5, max: 5 }).withMessage('日期参数格式错误：mm-dd')
];

/**
 * @description 历史上的今天列表
 * @param {string}  date   - 12-31 格式 MM-dd
 */
app.get('/', validator, (req, res) => {
  let err = validationResult(req);
  if (!err.isEmpty()) {
    return res.api_error(err.mapped().date.msg, 1002, err.mapped());
  }
  queryList(req, res);
});

module.exports = app;
